IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GetUserInstitution]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[GetUserInstitution]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

/******************************************************************
* VSS File Path: $Archive: /PHSRAG/Applications/WebApplications/Insight_Dev/Database/StoredProcedures/GetUserInstitution.sql $
* Gets user insititution to put into the user Context
*
* PARAMETERS
* Name    				Description					
* -------------  		---------------------------------------
* @userName			The user's userName
*
* RESULT SET
* Name    			Description					
* --------------	-------------------------------------------
* GetUserInstitution
*
* RETURN VALUE
* Value    			Description					
* --------------	-------------------------------------------
* N/A				N/A
*
******************************************************************/
CREATE Procedure dbo.GetUserInstitution (
		@domainUserId	  AS INT
)
AS

BEGIN

	SET NOCOUNT ON

	select fdo.Institution
	from AdmInternalPerson ap
	inner join AdmPerson app
	on app.Id = ap.AdmPersonId
	inner join FwkDomainOrganization fdo
	on ap.PrimaryOrganizationId = fdo.Id
	where app.FwkDomainUserId = @domainUserId

END

GO
